package com.njlime.member.repository.app;

import com.njlime.cms.entities.PublishReport;
import com.njlime.core.base.repository.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AppPublishReportDaoImpl extends BaseDaoImpl<PublishReport>{

    /**
     * 获取发布统计记录
     * @param date
     * @param id
     * @param unit_id
     * @param business_type
     * @return
     */
	public Map<String,Object> findReport(String date, Integer id, Integer unit_id, Integer business_type){
        StringBuffer sb = new StringBuffer();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_publish_report where date = ? and business_id = ? and unit_id = ? and business_type = ? ");
        arrList.add(date);
        arrList.add(id);
        arrList.add(unit_id);
        arrList.add(business_type);
        List<Map<String,Object>> list =  getListJdbc(sb.toString(),arrList);
        if(list != null && list.size() > 0){
            return list.get(0);
        }
        return null;
	}

    /**
     * 更新发布统计阅读数
     * @param id
     */
	public void updateReading(Integer id){
        StringBuffer sb = new StringBuffer();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("update t_publish_report set reading = reading + 1 where id = ? ");
        arrList.add(id);
        updateJdbc(sb.toString(),arrList);
    }
}
